/**
 * Description:
 * Class Name:PriorityTest
 * Date:2022/5/6 11:06
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第16章_多线程._16_4_控制线程._16_4_4_改变线程优先级;

public class PriorityTest extends Thread{
    public PriorityTest(String name){
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 50; i++) {
            System.out.println(getName() + "_" + i + "，其优先级是：" + getPriority());
        }
    }

    public static void main(String[] args) {
        // 改变主线程的优先级
        Thread.currentThread().setPriority(6);
        for (int i = 0; i < 30; i++) {
            if (i == 10){
                var low = new PriorityTest("低级");
                low.start();
                System.out.println("创建之初的优先级：" + low.getPriority());
                // 设置为最低优先级
                low.setPriority(MIN_PRIORITY);
            }
            if (i == 20){
                var high = new PriorityTest("高级");
                high.start();
                System.out.println("创建之初的优先级：" + high.getPriority());
                // 设置为最高优先级
                high.setPriority(MAX_PRIORITY);
            }
        }
    }
}
